package com.liu.controller;

import com.liu.dto.PetAddDto;
import com.liu.dto.PetUserEmpDto;
import com.liu.entity.Pet;
import com.liu.service.intf.PetService;
import com.liu.vo.PageBeanJson;
import com.liu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/pet/")
public class PetController {
    @Autowired
    private PetService service;
    //新增
    @PostMapping("save.do")
    public R save(Pet pet){
        System.out.println(pet);
        return service.save(pet);
    }
    @PostMapping("save1.do")
    public R save1(PetAddDto petAddDto){
        System.out.println(petAddDto);
        return service.save1(petAddDto);
    }
    //修改
    @PostMapping("update.do")
    public R update(Pet pet){

        return service.update(pet);
    }
    //删除
    @PostMapping("del.do")
    public R del(int id){
        return service.del(id);
    }
    //查询
    @GetMapping("page.do")
    public PageBeanJson page(int page, int limit){

        return service.queryPage(page, limit);
    }
    //查询 条件
    @GetMapping("pagewhere.do")
    public PageBeanJson page(String pname,int page,int limit){
        return service.queryPageWhere(pname,page, limit);
    }
    //批量删除 JSON格式的数据请求
    @PostMapping("delbatch.do")
    public R del(@RequestBody int[] ids){
        return service.delBatch(ids);
    }
    @GetMapping("pageCountByName.do")
    public PageBeanJson pageDto(String pname,int page,int limit) {
        return service.selectCountbyName(pname, page, limit);
    }
    @GetMapping("pageCount.do")
    public PageBeanJson pageDto(int page,int limit) {

        return service.selectCount(page, limit);
    }
    @PostMapping("adopt.do")
    public R save(PetUserEmpDto petUserEmpDto){

        return service.adopt(petUserEmpDto);
    }
}
